<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-form ref="form" :model="userids" :rules="rules" label-width="100px" id="mvcfm">
      <div class="form-unit">
        <span class="mvc-title-left"> 消息 </span>
      </div>
      <div>
        <el-row>
          <el-col :span="24">
            <el-form-item label="电话号码" prop="number">
              <el-input type="textarea" v-model="userids.number" />
              <el-button @click="popPhoneCustomerChoice('','number')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <input type="hidden" id="userids" name="userids" :value="userids.userids">
        <el-row>
          <el-col :span="24">
            <el-form-item label="短信内容" prop="phones_message">
              <el-input type="textarea" v-model="userids.phones_message" />
              <el-button @click="popMesChoice('','phones_message')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <el-button @click="newSmsSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>发送</el-button>
    </el-form>
    <el-dialog :visible.sync="PhoneCustomerChoiceVisible" append-to-body>
      <PhoneCustomerChoice v-if="PhoneCustomerChoiceVisible" ref="PhoneCustomerChoice" :popparams="popparams"> </PhoneCustomerChoice>
    </el-dialog>
    <el-dialog :visible.sync="MesChoiceVisible" append-to-body>
      <MesChoice v-if="MesChoiceVisible" ref="MesChoice" :popparams="popparams"> </MesChoice>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import PhoneCustomerChoice from "@/views/oa/communication/PhoneCustomerChoice";
  import MesChoice from "@/views/oa/communication/MesChoice";
  export default {
    name: 'NewSms',
    components: {
      PhoneCustomerChoice,
      MesChoice,
    },
    props: ['popparams'],
    data() {
      return {
        PhoneCustomerChoiceVisible: false,
        PhoneCustomerChoiceValue: null,
        PhoneCustomerChoiceDesc: null,
        MesChoiceVisible: false,
        MesChoiceValue: null,
        MesChoiceDesc: null,
        vueparams: this.getVUEParams(""),
        userids: {
          number: null,
          phones_message: null,
        },
        loading: false,
        rules: {}
      }
    },
    created() {
      this.getData();
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/oa/communication/SmsAction/newSms?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      newSmsSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/oa/communication/SmsAction/newSmsSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/oa/communication/NewSms/newSms?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      popPhoneCustomerChoice(desc, value) {
        this.PhoneCustomerChoiceVisible = true;
        this.PhoneCustomerChoiceDesc = desc;
        this.PhoneCustomerChoiceValue = value;
      },
      closePhoneCustomerChoice(value, desc) {
        this.PhoneCustomerChoiceVisible = false;
        this.$set(this.userids, this.PhoneCustomerChoiceDesc, desc);
        this.$set(this.userids, this.PhoneCustomerChoiceValue, value);
      },
      popMesChoice(desc, value) {
        this.MesChoiceVisible = true;
        this.MesChoiceDesc = desc;
        this.MesChoiceValue = value;
      },
      closeMesChoice(value, desc) {
        this.MesChoiceVisible = false;
        this.$set(this.userids, this.MesChoiceDesc, desc);
        this.$set(this.userids, this.MesChoiceValue, value);
      },
    },
  }
</script>
